<template>
    <div>
        <el-form-item label="工作地点">
            <el-input v-model='aaa' style="width:215px" placeholder="工作地点" id="address"></el-input>
        </el-form-item>
        <div class="map">
            <div id="container">
        
            </div>
        </div>
        
    </div>
    
</template>

<script>
var map, addMarker;
    var geocoder;
    var placeSearch;
    var lnglatXY;
    var t=1;
export default {
    data() {
        return {
            aaa:''
        };
    },
    mounted(){
        this.drawmap();
    },
    methods: {
        drawmap(){
             var map = new AMap.Map("container", {
                resizeEnable: true,
                zoom: 15,
                center: [113.133428, 27.828682]
            });
    
    var geocoder = new AMap.Geocoder({
        city: "010", //城市设为北京，默认：“全国”
    });
    
    var marker = new AMap.Marker();
    
    function geoCode() {
        var address  = document.getElementById('address').value;
        geocoder.getLocation(address, function(status, result) {
            console.log(status,result.info,'123')
            if (status === 'complete'&&result.geocodes.length) {
                var lnglat = result.geocodes[0].location
                document.getElementById('lnglat').value = lnglat;
                marker.setPosition(lnglat);
                map.add(marker);
                map.setFitView(marker);
            }else{
                console.log('根据地址查询位置失败');
            }
        });
    }
    // document.getElementById("geo").onclick = geoCode;
    document.getElementById('address').onkeydown = function(e) {
        if (e.keyCode === 13) {
            geoCode();
            return false;
        }
        return true;
    };
        }
    }
};
</script>
<style lang="css" scoped>
    #container{
        width: 100%;
        height: 100%;
        position:static;
    }
    .map{
        margin-left: 100px;
        width: 220px;
        height: 150px;
        background: #ccc;
    }
</style>
